package com.train.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.train.common.service.MinioService;
import com.train.common.utils.StringUtils;
import com.train.course.domain.VideoAction;
import com.train.course.domain.VideoEpisode;
import com.train.course.mapper.VideoActionMapper;
import com.train.course.mapper.VideoEpisodeMapper;
import com.train.course.service.IVideoActionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 分解动作视频 服务层实现
 */
@Service
public class VideoActionServiceImpl implements IVideoActionService {

    @Resource
    private VideoActionMapper videoActionMapper;
    @Resource
    VideoEpisodeMapper videoEpisodeMapper;
    @Resource
    private MinioService minioService;

    /**
     * 查询分解动作视频信息
     *
     * @param actionId 分解动作视频ID
     * @return 分解动作视频信息
     */
    @Override
    public VideoAction selectVideoActionById(Long actionId) {
        return videoActionMapper.selectVideoActionById(actionId);
    }

    /**
     * 查询分解动作视频列表
     *
     * @param videoAction 分解动作视频信息
     * @return 分解动作视频集合
     */
    @Override
    public List<VideoAction> selectVideoActionList(VideoAction videoAction) {
        return videoActionMapper.selectVideoActionList(videoAction);
    }

    /**
     * 根据视频集ID查询分解动作视频列表
     *
     * @param episodeId 视频集ID
     * @return 分解动作视频集合
     */
    @Override
    public List<VideoAction> selectVideoActionListByEpisodeId(Long episodeId) {
        List<VideoAction> videoActions = videoActionMapper.selectVideoActionListByEpisodeId(episodeId);
        VideoEpisode videoEpisode = videoEpisodeMapper.selectVideoEpisodeById(episodeId);
        Long viewCount = videoEpisode.getViewCount() + 1L;
        videoEpisode.setViewCount(viewCount);
        System.out.println("视频播放量增加"+viewCount);
        videoEpisodeMapper.updateVideoEpisode(videoEpisode);
        return videoActions;
    }

    /**
     * 新增分解动作视频
     *
     * @param videoAction 分解动作视频信息
     * @return 结果
     */
    @Override
    public int insertVideoAction(VideoAction videoAction) {
        return videoActionMapper.insertVideoAction(videoAction);
    }

    /**
     * 修改分解动作视频
     *
     * @param videoAction 分解动作视频信息
     * @return 结果
     */
    @Override
    public int updateVideoAction(VideoAction videoAction) {
        return videoActionMapper.updateVideoAction(videoAction);
    }

    /**
     * 删除分解动作视频信息
     *
     * @param actionId 分解动作视频ID
     * @return 结果
     */
    @Override
    public int deleteVideoActionById(Long actionId) {
        return videoActionMapper.deleteVideoActionById(actionId);
    }

    /**
     * 批量删除分解动作视频信息
     *
     * @param actionIds 需要删除的分解动作视频ID数组
     * @return 结果
     */
    @Override
    public int deleteVideoActionByIds(Long[] actionIds) {
        return videoActionMapper.deleteVideoActionByIds(actionIds);
    }
}